package controller

import (
	"sale-admin/internal/app/web/service/robot"

	"192.168.1.75/go-pkg/errorx"
	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

type StareCount struct{}

func (StareCount) List(c *gin.Context) {
	var params struct {
		StartTime  int64     `json:"start_time"`
		EndTime    int64     `json:"end_time"`
		ShopID     *[]string `json:"shop_id"`
		ProvinceID string    `json:"province_id"`
		CityID     string    `json:"city_id"`
		DistrictID string    `json:"district_id"`
		LocationID string    `json:"location_id"`
		RobotID    string    `json:"robot_id"`
		Type       int       `json:"type"`
		Page       int       `json:"page"`
		Limit      int       `json:"limit"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	merchantID := c.GetString("merchant_id")
	var shopIDList = []string{}
	if params.ShopID != nil {
		shopIDList = append(shopIDList, *params.ShopID...)
	}
	if params.Type == 1 { // 1 客群画像
		list, total, summary, err := robot.StareCount{}.StareCountList(c.Request.Context(), merchantID, shopIDList, params.StartTime,
			params.EndTime, params.ProvinceID, params.CityID, params.DistrictID, params.LocationID, params.RobotID, params.Page, params.Limit)
		response.JSON(c, gin.H{
			"summary": summary,
			"list":    list,
			"total":   total,
		}, err)
	} else if params.Type == 2 { // 2 凝视曝光比
		list, total, summary, err := robot.StareCount{}.StareFaceCountList(c.Request.Context(), merchantID, shopIDList, params.StartTime,
			params.EndTime, params.ProvinceID, params.CityID, params.DistrictID, params.LocationID, params.RobotID, params.Page, params.Limit)
		response.JSON(c, gin.H{
			"summary": summary,
			"list":    list,
			"total":   total,
		}, err)
	} else {
		response.JSON(c, nil, errorx.New("类型错误", -1))
	}
}
